package com.google.code.bankagregator.adapter.bank.imex;

import com.google.code.bankagregator.adapter.Adapter;
import com.google.code.bankagregator.adapter.bank.imex.parser.credit.ImexAutoCreditParser;
import com.google.code.bankagregator.adapter.bank.imex.parser.credit.ImexConsCreditParser;
import com.google.code.bankagregator.adapter.bank.imex.parser.deposit.ImexDepPatronParser;
import com.google.code.bankagregator.adapter.bank.imex.parser.deposit.ImexDepProfitParser;
import com.google.code.bankagregator.adapter.exception.AdapterException;
import com.google.code.bankagregator.entities.Credit;
import com.google.code.bankagregator.entities.Deposit;
import com.google.code.bankagregator.vo.AdapterResult;
import com.google.code.bankagregator.vo.AdapterWarning;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kirill
 * Date: 13.06.13
 * Time: 3:14
 * To change this template use File | Settings | File Templates.
 */
public class AdapterImex implements Adapter {

    @Override
    public AdapterResult getResult() {
        AdapterResult result = new AdapterResult();

        List<Credit> credits = new ArrayList<Credit>();
        List<Deposit> deposits = new ArrayList<Deposit>();
        List<AdapterWarning> warnings = new ArrayList<AdapterWarning>();

        List<Credit> creditList = null;
        List<Deposit> depositList = null;

        try {
            creditList = new ImexAutoCreditParser().getCredit();
            credits.addAll(creditList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            creditList = new ImexConsCreditParser().getCredit();
            credits.addAll(creditList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }


        try {
            depositList = new ImexDepPatronParser().getEURDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ImexDepPatronParser().getUAHDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ImexDepPatronParser().getUSDDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }

        try {
            depositList = new ImexDepProfitParser().getUAHDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ImexDepProfitParser().getUSDDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }
        try {
            depositList = new ImexDepProfitParser().getEURDeposit();
            deposits.addAll(depositList);
        } catch (AdapterException e) {
            warnings.add(new AdapterWarning(e.getMessage()));
        }

        // FIXME next lines fails
//        try {
//            depositList = new ImexDepThreeWishesParser().getUAHDeposit();
//            deposits.addAll(depositList);
//        } catch (AdapterException e) {
//            warnings.add(new AdapterWarning(e.getMessage()));
//        }


        result.setCredits(credits);
        result.setDeposits(deposits);
        result.setWarnings(warnings);


        return result;
    }
}
